package example.demo.datasouce;

import java.util.ArrayList;
import java.util.List;

public class DynamicDataSourceContextHolder {
    /*这个是 所有数据源的name，@TargetDatasource(name) 这里的name*/
    public static List<String> dataSourceIds = new ArrayList<>();

    /*当前线程正在使用的数据源的name*/
    private static final ThreadLocal<DBTypeEnum> contextHolder = new ThreadLocal<>();

    public static ThreadLocal<DBTypeEnum> getContextHolder() {
        return contextHolder;
    }

    public static void setDataSourceType(DBTypeEnum dataSourceType) {
        contextHolder.set(dataSourceType);
    }

    public static DBTypeEnum getDataSourceType() {
        return contextHolder.get();
    }

    public static boolean containsDataSource(String dataSourceId) {
        return dataSourceIds.contains(dataSourceId);
    }
}
